package org.jivesoftware.smack.packet;

import org.jivesoftware.smack.util.StringUtils;

public abstract class IQ extends Packet
{
  private Type type = Type.GET;

  public IQ()
  {
  }

  public IQ(IQ paramIQ)
  {
    super(paramIQ);
    this.type = paramIQ.getType();
  }

  public Type getType()
  {
    return this.type;
  }

  public void setType(Type paramType)
  {
    if (paramType == null)
      this.type = Type.GET;
    else
      this.type = paramType;
  }

  public String toXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<iq ");
    if (getPacketID() != null)
      localStringBuilder.append("id=\"" + getPacketID() + "\" ");
    if (getTo() != null)
      localStringBuilder.append("to=\"").append(StringUtils.escapeForXML(getTo())).append("\" ");
    if (getFrom() != null)
      localStringBuilder.append("from=\"").append(StringUtils.escapeForXML(getFrom())).append("\" ");
    if (this.type == null)
      localStringBuilder.append("type=\"get\">");
    else
      localStringBuilder.append("type=\"").append(getType()).append("\">");
    String str = getChildElementXML();
    if (str != null)
      localStringBuilder.append(str);
    XMPPError localXMPPError = getError();
    if (localXMPPError != null)
      localStringBuilder.append(localXMPPError.toXML());
    localStringBuilder.append("</iq>");
    return localStringBuilder.toString();
  }

  public abstract String getChildElementXML();

  public static IQ createResultIQ(IQ paramIQ)
  {
    if ((paramIQ.getType() != Type.GET) && (paramIQ.getType() != Type.SET))
      throw new IllegalArgumentException("IQ must be of type 'set' or 'get'. Original IQ: " + paramIQ.toXML());
    IQ local1 = new IQ()
    {
      public String getChildElementXML()
      {
        return null;
      }
    };
    local1.setType(Type.RESULT);
    local1.setPacketID(paramIQ.getPacketID());
    local1.setFrom(paramIQ.getTo());
    local1.setTo(paramIQ.getFrom());
    return local1;
  }

  public static IQ createErrorResponse(IQ paramIQ, XMPPError paramXMPPError)
  {
    if ((paramIQ.getType() != Type.GET) && (paramIQ.getType() != Type.SET))
      throw new IllegalArgumentException("IQ must be of type 'set' or 'get'. Original IQ: " + paramIQ.toXML());
    IQ local2 = new IQ()
    {
      public String getChildElementXML()
      {
        return IQ.this.getChildElementXML();
      }
    };
    local2.setType(Type.ERROR);
    local2.setPacketID(paramIQ.getPacketID());
    local2.setFrom(paramIQ.getTo());
    local2.setTo(paramIQ.getFrom());
    local2.setError(paramXMPPError);
    return local2;
  }

  public static class Type
  {
    public static final Type GET = new Type("get");
    public static final Type SET = new Type("set");
    public static final Type RESULT = new Type("result");
    public static final Type ERROR = new Type("error");
    private String value;

    public static Type fromString(String paramString)
    {
      if (paramString == null)
        return null;
      paramString = paramString.toLowerCase();
      if (GET.toString().equals(paramString))
        return GET;
      if (SET.toString().equals(paramString))
        return SET;
      if (ERROR.toString().equals(paramString))
        return ERROR;
      if (RESULT.toString().equals(paramString))
        return RESULT;
      return null;
    }

    private Type(String paramString)
    {
      this.value = paramString;
    }

    public String toString()
    {
      return this.value;
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.packet.IQ
 * JD-Core Version:    0.6.1
 */